
/**
 * AppleIIGo
 * KeyDown List class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "KeyDownList.h"

KeyDownList::~KeyDownList() {
	setStart();
	while (isNext())
		delete (UINT32 *) remove();
}

void KeyDownList::pushKey(UINT32 sym) {
	if (!findKey(sym)) {
		UINT32 * symp = new UINT32;
		*symp = sym;
		insert(symp);
	}
}

void KeyDownList::pullKey(UINT32 sym) {
	if (findKey(sym))
		remove();
}

UINT32 KeyDownList::getKey() {
	UINT32 * symp = (UINT32 *) get();
	return * symp;
}

bool KeyDownList::isAnyKeyDown() {
	setStart();
	return isNext();
}

bool KeyDownList::findKey(UINT32 sym) {
	for (setStart(); isNext(); next()) {
		UINT32 * symp = (UINT32 *) get();
		if (*symp == sym)
			return true;
	}

	return false;
}
